import {Component, OnInit} from '@angular/core';
import {WebsiteService} from '../../../service/website.service';

@Component({
  selector: 'app-mall',
  templateUrl: './mall.component.html',
  styleUrls: ['./mall.component.css']
})
export class MallComponent implements OnInit {
  goodsTypes = []; // 商品分类信息（包含商品信息）

  /**
   * 构造函数
   */
  constructor(private websiteService: WebsiteService) {
  }

  /**
   * 初始化函数
   */
  ngOnInit() {
    // 查询封面类别信息，包含封面信息
    this.websiteService.selectCoverTypeJoinCover({names: ['二维码']}).subscribe(coverTypeRes => {
      if (coverTypeRes.code === 0) {
        coverTypeRes.data.map(coverType => {
          if (coverType.name.includes('二维码')) {
            this.websiteService.pushWebsiteVariable({weixinCodeCovers: coverType.children}); // 推送消息对象到父组件
          }
        });
      }
    }, () => {}, () => {
      // 查询商品类别信息，包含商品信息
      this.websiteService.selectGoodsTypeJoinGoods({}).subscribe(goodsTypeRes => {
        if (goodsTypeRes.code === 0) {
          this.goodsTypes = goodsTypeRes.data;
        }
      });
    });
  }

}
